package development;

import java.util.Hashtable;

import javax.microedition.lcdui.Graphics;

import state.GameForm;
import state.TimerListener;
import state.font.FontManager;
import state.font.ImageText;
import state.util.Color;

public class FrmTestSinkText extends GameForm implements TimerListener {
  private final String TEXT_TO_SHINK = "text8 = FontManager.getFont(FontManager.FONT_SIZE_8);";
  private final int STEP = 5;
  
  private int x;
  private int textWidth;
  
  private boolean isMoveToLeft;
  
  private ImageText text11;
  
  private int leftLimit;
  private int rightLimit;
  
  private String allText = "AÁÀẢÃẠĂẮẰẲẴẶÂẤẦẨẪẬBCDĐEÉÈẺẼẸÊẾỀỂỄỆFGHIÍÌỈĨỊJKLMNOÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢPQRSTUÚÙỦŨỤƯỨỪỬỮỰVWSYÝỲỶỸỴZ aáàảãạăắằẳẵặâấầẩẫậbcdđeéèẻ ẽẹêếềểễệfghiíìỉĩịjklmnoóòỏõọôốồổỗộơớờởỡợpqrstuúùủũụưứừửữựvwsyýỳỷỹỵz0123456789-=\\!@#$%^&*()_+|{}:”<>?[];’,./ ";
  
  private static GameForm singleton;
  
  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmTestSinkText();
    }
    return singleton;
  }
  
  public void init(Hashtable parameters) {
    manager.setBackGroundColor(Color.BLACK_CODE);
    x = Constants.SCREEN_HEIGHT;
    y = 100;
    leftLimit = 0;
    rightLimit = Constants.SCREEN_WIDTH;
    
    text11 = FontManager.getFont(FontManager.FONT_SIZE_11);
    textWidth = text11.stringWidth(TEXT_TO_SHINK);
    isMoveToLeft = true;
    
    setTimerListener(this);
  }
  
  public void draw(Graphics g) {
    text11.drawParagraph(g, allText, Color.WHITE_CODE, 200, 10, 10);
  }
  
  public void doTask() {
    if (isMoveToLeft) {
      x -= STEP;
      if (x + textWidth < rightLimit - 30) {
        isMoveToLeft = !isMoveToLeft;
      }
    } else {
      x += STEP;
      if (x > leftLimit + 30) {
        isMoveToLeft = !isMoveToLeft;
      }
    }
  }
  
  protected void destroy() {
  }
}
